package com.itheima.d0_pritatic;

import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);


        ArrayList<Student> list = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            Student student = new Student();
            System.out.println("请录入第" + (i + 1) + "个学生信息");
            System.out.println("语文成绩");
            int chineseScore = scanner.nextInt();
            student.setChineseScore(chineseScore);

            System.out.println("姓名");
            String name = scanner.next();
            student.setName(name);
            System.out.println("数学成绩");
            int matchScore = scanner.nextInt();
            student.setMatchScore(matchScore);
            System.out.println("英语成绩");
            int englishScore = scanner.nextInt();
            student.setEnglishScore(englishScore);

            student.setZongfen(student.getChineseScore() + student.getEnglishScore() + student.getMatchScore());


            list.add(student);

            list.sort(new Comparator<Student>() {
                @Override
                public int compare(Student o1, Student o2) {
                    return o2.getZongfen() - o1.getZongfen();
                }
            });
        }
        try {
            FileOutputStream fw = new FileOutputStream("day14junit-reflect-annotation-proxy-app/src/score.txt", true);
            PrintStream printStream = new PrintStream(fw);
            FileReader fr = new FileReader("day14junit-reflect-annotation-proxy-app/src/score.txt");
            BufferedReader br = new BufferedReader(fr);

            printStream.println("文件中的数据展示如下");
            printStream.println("姓名，语文成绩，数学成绩，英语成绩");
            for (Student student : list) {

                printStream.println(student.toString());

            }

            String str;

            while ((str=br.readLine())!=null){
                System.out.println(str);

            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
